<template>
	<view class="container">
		<!-- 用户信息 -->
		<view class="user_section">
			<image src="../../static/img/userCenter/user_bg.jpg" class="bg">
			</image>
			<!-- 信息 -->
			<view class="user_info_box">
				<!-- 登陆 -->
				<view class="login">
					<!-- 头像框 -->
					<view class="head_portrai_box">
						<image src="../../static/img/user_picture.jpg" mode=""></image>
					</view>
					<view class="login_button" @tap="goToLogin">
						{{ nickname ? nickname : '立即登陆' }}
					</view>
				</view>
				<!-- 会员 -->
				<view class="vip">
					<u-row class="vip_info">
						<u-col span="1">
							<u-icon name="level" color="#CD7F32" size="30px"></u-icon>
						</u-col>
						<u-col span="8">
							<text class="vip_level">普通会员</text>
						</u-col>
						<!-- v-if="isOpenVip === false" -->
						<u-col span="3" @tap="goToOpen" v-if="isOpenVip !== true">
							<view class="open_vip">
								立即开通
							</view>
						</u-col>
					</u-row>
					<!-- 会员权限 -->
					<view class="vip_equity">
						<text>VIP权益</text>
						<view class="open">
							请联系管理员开通
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 功能部分 -->
		<view class="cover-container" :style="[{
				transform: coverTransform,
				transition: coverTransition
			}]" @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
			<image class="arc" src="../../static/img/userCenter/arc.png"></image>
			<view class="option_section">
				<!-- 资产 -->
				<u-row class="assets_box" @tap="goToWallet">
					<u-col span="4" textAlign="center">
						<view class="assets_num">{{hy_balance}}</view>
						<text>火源</text>
					</u-col>
					<u-col span="4" textAlign="center">
						<view class="assets_num">{{yl_balance}}</view>
						<text>原力</text>
					</u-col>
					<u-col span="4" textAlign="center">
						<view class="assets_num">{{hs_balance}}</view>
						<text>火石</text>
					</u-col>
				</u-row>
				<!-- 功能 -->
				<view class="function_box">
					<view @tap="goToPayment" class="function_box_item">
						<view>
							<image src="../../static/img/userCenter/pay.svg"></image>
						</view>
						<text>支付</text>
					</view>
					<view @tap="goToTransfer" class="function_box_item">
						<view>
							<image src="../../static/img/userCenter/transfer.svg"></image>
						</view>
						<text>转账</text>
					</view>
					<view @tap="goToExchange" class="function_box_item">
						<view>
							<image src="../../static/img/userCenter/duihuan.svg"></image>
						</view>
						<text>兑换</text>
					</view>
					<view @tap="goToRecharge" class="function_box_item">
						<view>
							<image src="../../static/img/userCenter/tixian.svg"></image>
						</view>
						<text>充值</text>
					</view>
					<view @tap="goToWithdrawa" class="function_box_item">
						<view>
							<image src="../../static/img/userCenter/after-sales.svg"></image>
						</view>
						<text>提现</text>
					</view>
				</view>
				<!-- 设置 -->
				<view class="set_box">
					<list-cell v-for="item in listCell" :key="item.func" :listName="item.listName" :imgSrc="item.src"
						@changeFunc="changeFunc(item.func)"></list-cell>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	import {
		createWallet,
		getWalletDetail
	} from '@/config/api.js';
	export default {
		data() {
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				footprintList: [],
				isVip: false,
				// 用户昵称
				nickname: '',
				// 是否开通VIP
				isOpenVip: false,
				// 客户号
				customerNo: '',
				// 账户余额
				hy_balance: 0,
				yl_balance: 0,
				hs_balance: 0,
				listCell: [{
						listName: '我的订单',
						src: '../../static/img/userCenter/order.png',
						func: 'order'
					},
					{
						listName: '我的NFT',
						src: '../../static/img/nft/liwu.png',
						func: 'nft'
					},
					{
						listName: '我的文章',
						src: '../../static/img/userCenter/article.png',
						func: 'article'
					},
					{
						listName: '我的任务',
						src: '../../static/img/userCenter/task.png',
						func: 'task'
					},
					{
						listName: '我的账单',
						src: '../../static/img/userCenter/bill.png',
						func: 'bill'
					},
					{
						listName: '退出登陆',
						src: '../../static/img/userCenter/bill.png',
						func: 'exit'
					}
				]
			};
		},
		onShow() {
			this.isOpenVip = uni.getStorageSync('isOpenVip')
			this.nickname = uni.getStorageSync('nickname')
			// 客户编号
			this.customerNo = uni.getStorageSync('customerNo')
			getWalletDetail({
				customerNo: this.customerNo,
				ccy: 0
			}).then(res => {
				console.log(res)
				this.hy_balance = res.data.balance
			})
			// 原力余额
			getWalletDetail({
				customerNo: this.customerNo,
				ccy: 1
			}).then(res => {
				console.log(res)
				this.yl_balance = res.data.balance
			})
		},
		created() {
			// console.log(this.customerNo)
			// 火源余额

		},
		methods: {
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			},
			// 登陆
			goToLogin() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			// 钱包
			goToWallet() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					// url: 'test?id=1&name=uniapp'  c传递参数
					url: "/pages/userCenter/wallet"
				})
			},
			// 支付
			goToPayment() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					url: "/pages/userCenter/payment"
				})
			},
			// 充值
			goToRecharge() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					url: "/pages/userCenter/recharge"
				})
			},
			// 提现
			goToWithdrawa() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					url: "/pages/userCenter/withdrawa"
				})
			},
			// 转账
			goToTransfer() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					url: "/pages/userCenter/transfer"
				})
			},
			// 兑换
			goToExchange() {
				if (this.isOpenVip !== true) return
				uni.navigateTo({
					url: "/pages/userCenter/exchange"
				})
			},
			// 开通
			goToOpen() {
				uni.navigateTo({
					url: "/pages/userCenter/open"
				})
			},
			// 退出
			exit() {
				uni.clearStorageSync();
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			// 操作判断
			changeFunc(val) {
				console.log(val)
				switch (val) {
					case 'task':
						uni.navigateTo({
							url: "/pages/my/myTask"
						})
						break;
					case 'exit':
						this.exit()
						break;
					default:
						console.log(2)
				}
			},
		}
	}
</script>

<style lang="scss">
	.user_section {
		height: 600rpx;
		position: relative;

		.bg {
			width: 100%;
			height: 100%;
		}

		.user_info_box {
			position: absolute;
			top: 60rpx;
			width: 100%;
			height: 300rpx;

			.login {
				padding: 30rpx;
				display: flex;
				align-items: center;

				.head_portrai_box {
					width: 140rpx;
					height: 140rpx;
					border-radius: 50%;
					margin-right: 40rpx;
					font-size: 40rpx;
					border: 2px solid white;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.login_button {
					color: white;
					font-size: 36rpx;
					font-weight: bold;
				}
			}

			.vip {
				margin: 0 30rpx;
				padding: 30rpx 30rpx;
				background-image: linear-gradient(to left, rgba(0, 0, 0, .7), rgba(0, 0, 0, .8));
				border-radius: 16upx 16upx 0 0;

				.vip_info {
					margin-bottom: 40rpx;

					.vip_level {
						margin-left: 20rpx;
						color: #CD7F32;
						font-size: 30rpx;
					}

					.open_vip {
						background-image: linear-gradient(to left, #f9e6af, #ffd465);
						text-align: center;
						border-radius: 20rpx;
						width: 150rpx;
					}
				}

				.vip_equity {

					text {
						color: #CD7F32;
						font-size: 30rpx;
					}

					.open {
						color: #777;
						font-size: $bsin-basin-font;
						margin-top: 16rpx;
						margin-bottom: 40rpx;
					}
				}
			}

		}
	}

	.cover-container {
		position: relative;
		z-index: 2;
		top: -280rpx;

		.arc {
			width: 100%;
			height: 100rpx;
		}

		.option_section {
			background-color: #F9F9F9;
			position: relative;
			top: -20rpx;

			.assets_box {
				padding: 20rpx;
				margin: 0 30rpx;
				background-color: #FFFFFF;

				.assets_num {
					font-size: $bsin-basin-font;
				}

				text {
					margin-top: 10rpx;
					color: #777;
				}
			}

			.function_box {
				display: flex;
				justify-content: space-between;
				padding: 40rpx 60rpx;
				margin: 30rpx;
				background-color: #FFFFFF;

				.function_box_item {
					text-align: center;

					image {
						width: 48rpx;
						height: 48rpx;
					}
				}

			}

			.set_box {
				margin: 30rpx;
				background-color: #FFFFFF;
				font-size: $bsin-basin-font;
			}
		}
	}
</style>
